package table.tablemodel;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import bank.Kunde;

public class KundenUebersichtTableModel extends AbstractTableModel {

	private static final long serialVersionUID = 100L;

    private static final String[] COLUMN_NAMES = {"Kundenname", "Kundennummer", "Anzahl Konten", "Kontostand (Alle Konten)"};

	private List<Kunde> kunden;


	@Override
	public int getColumnCount() {
		return COLUMN_NAMES.length;
	}

	@Override
	public int getRowCount() {
		return getKunden() == null ? 0 : getKunden().size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Kunde kunde = getKunden().get(rowIndex);
		switch (columnIndex) {
		    case 0:
		        return kunde.getName();

		    case 1:
		        return kunde.getKundennummer();

		    case 2:
		        return kunde.getKontenListe().size();

            case 3:
                return kunde.getGesammtKontostand();
		        
	        default:
		        throw new IllegalArgumentException("Unknown Column-Index '" + columnIndex +"'");
		}
	}

    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return String.class;

            case 1:
                return Integer.class;

            case 2:
                return Integer.class;

            case 3:
                return Double.class;
                
            default:
                throw new IllegalArgumentException("Unknown Column-Index '" + columnIndex +"'");
        }
    }

	@Override
    public String getColumnName(int colNr) {
		return COLUMN_NAMES[colNr];
	}

	public List<Kunde> getKunden() {
		return kunden;
	}

	public void setKunden(List<Kunde> aKunden) {
		kunden = aKunden;
		fireTableDataChanged();
	}
}
